﻿//-----------------------------------------------------------------------
// <copyright file="TestRepository.cs" company="ET">
//     Copyright Mulala. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Mulala.Cavan.UnitTest.TestRepository
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using NUnit.Framework;
    using Spring.Context;
    using Spring.Context.Support;
    using Mulala.Cavan.Domain.MainBoundedContext.ProprietorModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SecurityModule;
    using Mulala.Cavan.Infrastructure.Data.MainBoundedContext.SecurityModule;
    using Mulala.Cavan.Domain.MainBoundedContext.MulalaModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Domain.MainBoundedContext.DictionaryModule;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;

    [TestFixture]
    public class TestCustomerRepository
    {
        private IApplicationContext context;

        [SetUp]
        public void SetUp()
        {
            context = ContextRegistry.GetContext();
        }

        [Test]
        public void TestAddRole()
        {
            IRoleRepository roleRepository = context.GetObject(SecurityConst.ROLEREPOSITORY) as IRoleRepository;
            Role role = RoleFactory.CreateRole(SecurityIdentifier.Role.Proprietor.ToString(), "业主", true, null, null, DateTime.Now, SecurityIdentifier.Role.Administrator.ToString());
            roleRepository.Save(role);

            Assert.Greater(role.ID, 0);
        }

        [Test]
        public void TestAddProprietor()
        {
            //IRoleRepository roleRepository = context.GetObject(SecurityConst.ROLEREPOSITORY) as IRoleRepository;
            //IProprietorRepository proprietorRepository = context.GetObject(ProprietorConst.PROPRIETORREPOSITORY) as IProprietorRepository;
            //RoleSpecification  roleSpecification = new RoleSpecification();
            //roleSpecification.SearchParams = new Domain.MainBoundedContext.SearchModule.RoleSearch();
            //roleSpecification.SearchParams.Name = SecurityIdentifier.Role.Proprietor.ToString();
            //Role role = roleRepository.Get(roleSpecification);
            //IList<Role> roles = new List<Role>();
            //roles.Add(role);
            //UserAccount userAccount = UserAccountFactory.CreateUserAccount("proprietor1", "123456", "proprietor1@qq.com", 1, 1, 
            //                                                                1, 1, 1, 1, DateTime.Now, false, false, roles, null, 
            //                                                                null, null, null, DateTime.Now, "proprietor1");

            //ProprietorStatus proprietorStatus = ProprietorStatusFactory.CreateProprietorStatus(DateTime.Parse(Project.Settings.DefaultTime), DateTime.Parse(Project.Settings.DefaultTime), ProprietorIdentifier.CheckedStatus.UnChecked,
            //    ProprietorIdentifier.CheckedStatus.UnChecked, DateTime.Now, userAccount.Name);
            //Proprietor proprietor = ProprietorFactory.CreateProprietor(userAccount, "刘佳", false, "liujia@qq.com", false, null,
            //                                                            "1313442334", false, "江西萍乡", false, "", null, proprietorStatus, DateTime.Now, userAccount.Name);
            //proprietorRepository.Save(proprietor);

            //Assert.Greater(proprietor.ID, 0);
        }

        [Test]
        public void TestGetArea()
        {
            IAreaRepository areaRepository = context.GetObject("AreaRepository") as IAreaRepository;
            AreaSpecification areaSpecification = new AreaSpecification();
            areaSpecification.SearchParams = new AreaSearch();
            areaSpecification.SearchParams.ID = "0201";
            Area area = areaRepository.Get(areaSpecification);

            Assert.IsNotNull(area);
        }

        [Test]
        public void TestGetNanny()
        {
            INannyRepository nannyRepository = context.GetObject("NannyRepository") as INannyRepository;
            Nanny nanny = nannyRepository.Get(33);

            Assert.IsNotNull(nanny);
        }
    }
}
